<script setup lang="ts">
import { getProjectDetail } from "@/api/research/project";
import { FileUpload } from "@/components/common/FileUpload";
import { dealDataExcept, formatDate, isCanPreview } from "@/utils/common";
import { ref, watch } from "vue";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    verticalProjectName: "",
    startDate: "",
    endDate: "",
    firstAccountDate: "",
    secondAccountDate: "",
    level: "",
    contractFiles: "",
    projectType: 1,
    accountPrice: null,
    contractPrice: null,
    score: 0,
    examineStatus: 0,
    examineDesc: ""
  }),
  dataId: null,
  userList: null
});

watch(
  () => props.dataId,
  async newValue => {
    if (!newValue) {
      return;
    }
    getProjectDetail({ id: newValue }).then(res => {
      newFormInline.value = res.data;
    });
  },
  { immediate: true }
);

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    label-width="160px"
    :inline="true"
    class="add-form"
  >
    <el-form-item label="纵向项目名称" prop="verticalProjectName">
      <div>{{ newFormInline.verticalProjectName || "--" }}</div>
    </el-form-item>
    <el-form-item label="项目负责人" prop="projectMasterName" class="flex-1">
      <div>{{ newFormInline.projectMasterName || "--" }}</div>
    </el-form-item>
    <el-form-item label="项目参与人" prop="projectPartName" class="flex-1">
      <div>{{ newFormInline.projectPartName || "--" }}</div>
    </el-form-item>
    <el-form-item label="项目级别" prop="level" class="flex-1">
      <div>{{ newFormInline.level || "--" }}</div>
    </el-form-item>
    <el-form-item label="项目金额" prop="contractPrice" class="flex-1">
      <div>
        {{ dealDataExcept(newFormInline.contractPrice) || "--" }}
        <span v-if="newFormInline.contractPrice">万元</span>
      </div>
    </el-form-item>
    <el-form-item label="项目日期" prop="obtainDate" class="flex-1">
      <div v-if="newFormInline.startDate">
        {{ formatDate(newFormInline.startDate) }} ~
        {{ formatDate(newFormInline.endDate) }}
      </div>
      <div v-else>--</div>
    </el-form-item>

    <el-form-item label="申报日期" prop="firstAccountDate">
      <div>
        {{ formatDate(newFormInline.firstAccountDate, "--") }}
      </div>
    </el-form-item>
    <el-form-item label="获批日期" prop="hireDate">
      <div>
        {{ formatDate(newFormInline.secondAccountDate, "--") }}
      </div>
    </el-form-item>

    <div class="flex">
      <el-form-item label="获取积分" prop="score" class="flex-1">
        <div>{{ newFormInline.score || "--" }}</div>
      </el-form-item>

      <el-form-item label="到账金额" prop="accountPrice" class="flex-1">
        <div>
          {{ dealDataExcept(newFormInline.accountPrice) || "--" }}
          <span v-if="newFormInline.accountPrice">万元</span>
        </div>
      </el-form-item>
    </div>
    <el-form-item label="合同附件" prop="contractFiles">
      <FileUpload
        v-model="newFormInline.contractFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="立项证明文件" prop="projectCertsFiles">
      <FileUpload
        v-model="newFormInline.projectCertsFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="审核状态" prop="score">
      <el-tag v-if="newFormInline.examineStatus === 0" type="warning"
        >审核中</el-tag
      >
      <el-tag v-else-if="newFormInline.examineStatus === 1" type="primary"
        >已审核</el-tag
      >
      <el-tag v-else type="danger">已驳回</el-tag>
    </el-form-item>
    <el-form-item label="驳回原因" prop="score">
      <div>{{ newFormInline.examineDesc || "--" }}</div>
    </el-form-item>
    <el-form-item />
  </el-form>
</template>
